<%@ page language="java" contentType="text/html; charset=UTF-8"	 pageEncoding="UTF-8"%>
<%@ include file="../include/laypublic.jsp"%>
<!DOCTYPE html>
<html>
<head>
  <title>建投总部净利润新增</title>
</head>
<style>
	.fieldset{
		margin-top: 5px;
		margin-bottom: 0px
	}
	.layui-legend{
		background-color:#5fb878;
		width:140px;
	}
	.layui-form-item {
	    margin-bottom: 5px;
	    clear: both;
	    *zoom: 1;
	}
	.layui-form-label{width: 180px;}
	.right{
		float:right;
	}
	.width106{
		width:106px;
	}
	.width98{
		width:98px;
	}
	.width60{
		width:60px;
	}
	.width30{
		width:30px;
	}
</style>
<body>
<div class="layui-fluid">
    <div class="layui-card">
	    <div class="layui-tab-item layui-show">
	    	<div style="padding-top:15px;">&nbsp;</div>
			<form class="layui-form" id="addInfo_form">
					<div style="margin-top:20px"></div>					
				  	<div class="layui-form-item">
				      	<div class="layui-form-item">
						    <label class="layui-form-label">费用归属公司</label>
						    <div class="layui-input-inline">
						      	<input type="text" value="江苏中南建设集团上海投资发展有限公司" style="width:350px;border:0;" readonly="readonly" autocomplete="off" class="layui-input"/>
						    </div>
					    </div>
					    <div style="margin-top:16px"></div>	
					    <div class="layui-form-item">
						    <label class="layui-form-label">登记公司</label>
					      	<div class="layui-input-inline">
								<input type="hidden" name="hrOrgId" value="${bindOrgId}">
								<input type="text" value="${bindOrgName}" style="border:0px;" readonly="readonly" class="layui-input">
					      	</div>
					      	<div style="margin-top:16px"></div>	
					    	<label class="layui-form-label">登记部门</label>
				      		<div class="layui-input-inline">
				      			<input type="hidden" name="hrDeptId" value="${bindDeptId}">
								<input type="text" value="${bindDeptName}" style="border:0px;" readonly="readonly" class="layui-input">
				      		</div>
				      		<div style="margin-top:16px"></div>	
					    	<label class="layui-form-label">登记人</label>
				      		<div class="layui-input-inline">
				        		<input type="hidden" name="hrStaffApplyId" value="${SESSION_KEY_USER_DETAIL.hrStaffId }">
				        		<input type="text" name="staffName" value="${staffName }" readonly="readonly" style="border:0px" autocomplete="off" class="layui-input">
				      		</div>
			      		</div>
					</div>
					<div class="layui-form-item" >
						<div style="margin-top:16px"></div>	
							<div class="layui-form-item" >
							   <div class="layui-inline">
			             			<label class="layui-form-label">所属期间</label>
					             	<div class="layui-input-inline">
					               		<input type="text" class="layui-input" id="beeDate" name="monthWithoutDay" readonly placeholder="所属期间" lay-verify="required">
					             	</div>
			       				</div>
			       			</div>
       				</div>
					<div style="margin-top:16px"></div>	
					<hr></hr>
					<div class="layui-form-item">
					    <label class="layui-form-label">主营业务收入（元）</label>
				      	<div class="layui-input-inline">
							<div class="layui-input-inline">
			                    <input type="text" maxlength="13" onblur="isNumberFloat(this);arabiaToCN(this,1);" id="mainIncome" name="mainIncome"  lay-verify="required|floatAmount" 
			                          autocomplete="off" class="layui-input" placeholder="请输入主营业务收入">
			                </div>
				      	</div>
				      	<div style="margin-top:16px"></div>	
				    	 <label class="layui-form-label" >其他业务收入（元）</label>
			      		<div class="layui-input-inline">
			      			<div class="layui-input-inline">
			                    <input type="text" maxlength="13" onblur="isNumberFloat(this);arabiaToCN(this,1);" id="otherIncome" name="otherIncome"  lay-verify="required|floatAmount" 
			                           autocomplete="off" class="layui-input"  placeholder="请输入其他业务收入">
			                </div>
			      		</div>
		      		</div>
		      		<div class="layui-form-item" >
		           		<div class="layui-inline" style="width:100%;">
		                <label class="layui-form-label" ><B>收入合计</B>（元）</label>
		                <div class="layui-input-inline">
		                    <input type="text" style="border:0px;" readonly="readonly"  class="layui-input" id="incomeSum" name="incomeSum" 
		                           autocomplete="off" class="layui-input" value="0">
		                </div>
		                 </div>
		                 <div style="margin-top:16px"></div>
					</div>
					<div style="margin-top:16px"></div>
					<hr></hr>	
					<div class="layui-form-item">
					    <label class="layui-form-label" >管理费用（元）</label>
				      	<div class="layui-input-inline">
							<div class="layui-input-inline">
			                    <input type="text" maxlength="13" onblur="isNumberFloat(this);arabiaToCN(this,1);" id="manageBee" name="manageBee"  lay-verify="required|floatAmount" 
			                           autocomplete="off" class="layui-input" placeholder="请输入管理费用">
			                </div>
				      	</div>
				      	<div style="margin-top:16px"></div>	
				    	<label class="layui-form-label" >销售费用（元）</label>
			      		<div class="layui-input-inline">
			                    <input type="text" maxlength="13" onblur="isNumberFloat(this);arabiaToCN(this,1);" id="saleBee" name="saleBee" lay-verify="required|floatAmount" 
			                           autocomplete="off" class="layui-input" placeholder="请输入销售费用">
		                </div>
				        <div style="margin-top:16px"></div>	
				    	<label class="layui-form-label" >财务费用（元）</label>
			      		<div class="layui-input-inline">
		                    <input type="text" maxlength="13" onblur="isNumberFloat(this);arabiaToCN(this,1);" id="fiaBee" name="fiaBee"  lay-verify="required|floatAmount" 
		                           autocomplete="off" class="layui-input" placeholder="请输入财务费用">
		                </div>       
	      			</div>
	      			<div class="layui-form-item">
					    <label class="layui-form-label" ><B>费用合计</B>（元）</label>
				      	<div class="layui-input-inline">
			                    <input type="text" style="border:0px;"  readonly="readonly" id="outBeeSum" name="outBeeSum"
			                           autocomplete="off" class="layui-input"  value="0">
			                </div>
		      		</div>
			        <hr></hr>	  
					<div style="margin-top:16px"></div>
		            <div class="layui-form-item" style="width:100%;">
		            <label class="layui-form-label" >税金（元）</label>
		                <div class="layui-input-inline">
	                    	<input type="text" onblur="isNumberFloat(this);arabiaToCN(this,1);" id="faxBee"  name="faxBee"  lay-verify="required|doubleNumber" 
			                         maxlength="13" autocomplete="off" class="layui-input" placeholder="请输入税金">
		                </div>
		                <label class="layui-form-label">投资收益（元）</label>
		                <div class="layui-input-inline">
	                    	<input type="text" onblur="isNumberFloat(this);arabiaToCN(this,1);" id="investIncome" name="investIncome"  lay-verify="required|floatAmount" 
			                          maxlength="13" autocomplete="off" class="layui-input" placeholder="请输入投资收益">
		                </div>
		            </div>
			        <div style="margin-top:16px"></div>	  
		            <div class="layui-form-item" style="width:100%;">
		            	<label class="layui-form-label" ><B>利润总额</B>（元）</label>
		                <div class="layui-input-inline">
	                    	<input type="text" style="border:0px;" readonly="readonly" id="profitSum" name="profitSum" 
			                           autocomplete="off" class="layui-input" value="0"> 
		                </div>
		                 <label class="layui-form-label" >所得税（元）</label>
		                <div class="layui-input-inline">
	                    	<input type="text" id="incomeTax" name="incomeTax" onblur="isNumberFloat(this);arabiaToCN(this,1);"
			                           autocomplete="off" class="layui-input" placeholder="请输入所得税">
		                </div>
		            	<label class="layui-form-label" ><B>净利润</B>（元）</label>
		                <div class="layui-input-inline">
	                    	<input type="text" style="border:0px;" readonly="readonly" id="netProfit" name="netProfit" 
			                           autocomplete="off" class="layui-input" value="0">
		                </div>
		            </div>
		            <hr></hr>	
		            <div style="margin-top:16px"></div>
		            <div class="layui-form-item" style="width:100%;">
		            	<label class="layui-form-label" >资金周转利润（元）</label>
		                <div class="layui-input-inline">
	                    	<input type="text" onblur="isNumberFloat(this);arabiaToCN(this,1);" id="turnoverProfit" name="turnoverProfit" lay-verify="required|floatAmount" 
			                          maxlength="13" autocomplete="off" class="layui-input" placeholder="请输入资金周转利润">
		                </div>
		           </div>
		            <div style="margin-top:16px"></div>	
		            <div class="layui-form-item" style="width:100%;">
		                <label class="layui-form-label" ><B>管理利润</B>（元）</label>
		                <div class="layui-input-inline">
	                    	<input type="text" style="border:0px;" readonly="readonly" id="manageProfit" name="manageProfit" 
			                           autocomplete="off" class="layui-input" value="0">
		                </div>
		            </div>
		            <div style="margin-bottom:16px">&nbsp;</div>
				    <div class="layui-form-item" style="position: fixed ! important; right: 30px; bottom:45%;z-index:10000;">
						<div class="layui-input-block">
				      		<button class="layui-btn layui-bg-blue layui-btn-normal layui-btn-lg  layui-btn-radius" type="button" lay-submit lay-filter="addInfo_form_submit" id="addInfo_form_submit">
				      		<i class="layui-icon layui-icon-ok layuiadmin-button-btn"></i>
				      		提交
				      		</button>
				      	</div>
			      </div>			
			</form>
  		</div>
	</div>
</div>
  <script>

  layui.config({
    base: '${ctx}/resources/layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'set', 'upload', 'element', 'laydate'], function(){
    var $ = layui.$
    ,form = layui.form
    ,element = layui.element
    ,laydate = layui.laydate
    ,upload = layui.upload;
    
 	// 正则校验
	form.verify({
		//验证汉字
	    CHS:[
	    	/^[\u0391-\uFFE5]+$/
	    	,'只能输入汉字'
	  	],
	  	//大于0的正整数
	  	intNumber:[
			/^[1-9]\d*$/
			,'请输入正确的数字'
	  	],
	  	//数字只能有两位小数
	  	floatNumber:[
			/^([-]?)([0-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/
			,'请输入正确的数字'
	  	],
	  	//数字大于等于0，并只能有两位小数
	  	floatAmount:[
			/^([0-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/
			//var pattern=/^((\d+\.\d*[1-9]\d{1})|(\d*[1-9]\d*\.\d{2}))$/; 
			,'请输入正确的数字'
	  	]
	});
 	
	//费用期间
	    laydate.render({
	      elem: '#beeDate'
	      ,type: 'month'
	      ,format:'yyyy-MM'
	    });
	
	//项目名称select监听
    form.on('select(add_select_proId)', function(data){
    	var id = data.value;
    	$('#query-select-proId').html('');
    	getProPlotProId(id);   	
    }); 
   	//监听提交
  	form.on('submit(addInfo_form_submit)', function(data){
  		$("#addInfo_form_submit").removeAttr("lay-submit").removeClass("layui-bg-blue").addClass("layui-btn-disabled");
  		layer.load();
       	//提交 Ajax 成功后，静态更新表格中的数据
       	$.ajax({
           	type : 'post',
			url : basePath + '/superProfit/save',
           	data: $('#addInfo_form').serialize(),
			success:function(result){
				if(result.success){
					layer.closeAll('loading'); //关闭loading
					/* layer.msg('提交表单成功~',{icon: 1}); */
					//两秒后关闭当前页面
					setTimeout(function(){
						/**
						 * 查找父菜单，并刷新
						 */
						var topDoc = $(window.top.document);
						var path = basePath + '/superProfit/list';
						// 获取页面名称
						var name = topDoc.find(".layui-nav-item [lay-href^='" + path + "']").text();
						if(name == '' || name == null){
							name = '建投总部净利润';
						}
						window.parent.layui.index.openTabsPage(path, name);
						var iframe = window.parent.layui.admin.tabsBody(window.parent.layui.admin.tabsPage.index).find(".layadmin-iframe");
						iframe[0].contentWindow.location.reload(true);
						
						/**
						 * 关闭当前页
						 */
						var currPath = basePath + '/superProfit/add';
						var layid = topDoc.find("li[lay-id^='" + currPath + "']").attr('lay-id');
						window.parent.layui.element.tabDelete('layadmin-layout-tabs', layid);//关闭当前页
				        }, 2000);
				}else{
					layer.closeAll('loading'); //关闭loading
  					$("#addInfo_form_submit").removeClass("layui-btn-disabled").addClass("layui-bg-blue").attr("lay-submit","");
					layer.msg(result.msg,{icon: 7});
			  	}
			}
       	});
   	});  
 	// data-type事件
    $('.layui-btn.layuiadmin-btn-admin').on('click', function(){
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });
  	
  });
  
	//验证金额
	function isNumberFloat(obj){
		var $ = layui.$;
		if (obj.value == '' || obj.value == null) {
			return;
		}
		var rgx = /^([-]?)([0-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/;
		var boolrgx = rgx.test(obj.value);// true 
		if (!boolrgx){
			obj.value=0;
			layer.msg('请输入正确数字，且保留两位小数！');
		}
		incomeSumAmount();
	}
  
  //计算收入合计
  function incomeSumAmount(){
		var $ = layui.$;
		var mainIncome = $("#mainIncome").val();
		var otherIncome = $("#otherIncome").val();
		var manageBee = $("#manageBee").val();
		var saleBee = $("#saleBee").val();
		var fiaBee = $("#fiaBee").val();
		var investIncome = $("#investIncome").val();
		var faxBee = $("#faxBee").val();
		var turnoverProfit = $("#turnoverProfit").val();//
		var totalAmount = 0;   //收入合计
		var outBeeAmount = 0; //费用合计
		var profitAmount = 0;  //利润总额
		var manageProfit = 0;//管理利润
		if(mainIncome != '' && parseFloat(mainIncome) > 0){
			totalAmount = parseFloat(totalAmount) + parseFloat(mainIncome);
			totalAmount = totalAmount.toFixed(2);
		}
		if(otherIncome != '' && parseFloat(otherIncome) > 0){
			totalAmount = parseFloat(totalAmount) + parseFloat(otherIncome);
			totalAmount = totalAmount.toFixed(2);
		}
		profitAmount = totalAmount;
		if(manageBee != '' && parseFloat(manageBee) > 0){
			outBeeAmount = parseFloat(outBeeAmount) + parseFloat(manageBee);
			outBeeAmount = outBeeAmount.toFixed(2);
		}
		if(saleBee != '' && parseFloat(saleBee) > 0){
			outBeeAmount = parseFloat(outBeeAmount) + parseFloat(saleBee);
			outBeeAmount = outBeeAmount.toFixed(2);
		}
		if(fiaBee != '' && parseFloat(fiaBee) > 0){
			outBeeAmount = parseFloat(outBeeAmount) + parseFloat(fiaBee);
			outBeeAmount = outBeeAmount.toFixed(2);
		}
		if(investIncome != '' && parseFloat(investIncome) > 0){
			profitAmount = parseFloat(profitAmount) + parseFloat(investIncome);
			profitAmount = profitAmount.toFixed(2);
		}
		if(faxBee != '' && parseFloat(faxBee) > 0){
			profitAmount = parseFloat(profitAmount) - parseFloat(faxBee);
			profitAmount = profitAmount.toFixed(2);
		}
		
		if(turnoverProfit != '' && parseFloat(turnoverProfit) > 0){
			manageProfit = parseFloat(manageProfit) + parseFloat(turnoverProfit);
			manageProfit = manageProfit.toFixed(2);
		}
		profitAmount =  profitAmount -outBeeAmount ;//利润总额
		//profitAmount = profitAmount.toFixed(2);
		/* var incomeTax = totalAmount*0.25;//所得税 */
		var incomeTax = $("#incomeTax").val();
		if(incomeTax == null || incomeTax == ''){
			incomeTax = 0;
		}
		var netProfit = profitAmount - parseFloat(incomeTax); //净利润
		manageProfit = parseFloat(manageProfit)+parseFloat(netProfit); //管理利润
		$("#incomeSum").val(totalAmount);
		$("#outBeeSum").val(outBeeAmount);
		$("#profitSum").val(profitAmount.toFixed(2));
		//$("#incomeTax").val(incomeTax.toFixed(2));
		$("#netProfit").val(netProfit.toFixed(2));  //净利润
		$("#manageProfit").val(manageProfit.toFixed(2));  //管理利润
	}
  
  </script>
</body>
</html>